﻿<%@ Page MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="ProductDetail.aspx.cs" Inherits="RabbitShop.UI.ProductDetail" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    
    <form id="form1" action="/Action/GroupCartItemAdd.aspx" method="POST">
    <script type="text/javascript">
        function AddToCart() {
            var uid = getCookie("uid");
            if (uid == "") {
                window.location = "UserLogon.aspx";
                return;
            }
            var data = { "ShopId": "<%=shop.Id%>", "ProductId": "<%=product.Id%>" };
            for (var i = 0, ii = form1.length; i < ii; ++i) {
                var input = form1[i];
                if (input.name) {
                    data[input.name] = input.value;
                }
            }
            
            var xhr = new XMLHttpRequest();
            xhr.open(form1.method, form1.action, true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

            xhr.send(JSON.stringify(data));

            xhr.onloadend = function () {
                if (xhr.responseText == "true") {
                    window.location = "CartViewGroup.aspx";
                } else {
                    //alert(xhr.responseText);
                }
            };
        };
        function getCookie(c_name) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=");
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1;
                    c_end = document.cookie.indexOf(";", c_start);
                    if (c_end == -1) c_end = document.cookie.length;
                    return unescape(document.cookie.substring(c_start, c_end));
                }
            }
            return "";
        }

        function setCookie(c_name, value, expiredays) {
            var exdate = new Date();
            exdate.setDate(exdate.getDate() + expiredays);
            document.cookie = c_name + "=" + escape(value) +
                ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
        }
        function checkCookie() {
            username = getCookie('Id');
            if (username != null && username != "") {
                alert('Welcome again ' + username + '!');
            }
            else {
                username = prompt('Please enter your name:', "");
                if (username != null && username != "") {
                    setCookie('username', username, 365);
                }
            }
        }
        function updatenum(type) {
            var qty = parseInt(document.forms['form1'].elements['quantity'].value);
            if (type == 'sub') {
                if (qty > 1) {
                    document.forms['form1'].elements['quantity'].value = (qty - 1);
                }
            } else {
                document.forms['form1'].elements['quantity'].value = (qty + 1);
            }
        }
    </script>

        
    <table>
        <tr>
            <td>
                <a href="ProductListByShop.aspx?shopId=<%=shop.ShopId %>"><%=shop.NickName %></a>
            </td>
        </tr>
    </table>

    <table>
        
        <tr>
            <td>
                <img src="<%=product.MainImage %>" width="350" height="350"/>
            </td>
            <td style="width: 650px;">

                <div id="J_Title" class="tb-title" shortcut-key="t" shortcut-label="查看宝贝标题" shortcut-effect="focus">
                    <h3 class="tb-main-title" >
                        <%=product.Title %>
                    </h3>
                    <p class="tb-subtitle">
                        <%=product.SubTitle %>
                    </p>

                </div>
                    
                <table>
                    <tr>
                        <td>配送:</td>
                        <td><%=shop.Location.Province %><%=shop.Location.City %> 至 <%=address.Province %> <%=address.City %> <%=address.Region %></td>
                    </tr>
                    <tr>
                        <td style="width: 60px;">运费:</td>
                        <td><%=shop.DiliveryCostDescription %></td>
                    </tr>
                    <tr>
                        <td>价格:</td>
                        <td><%=product.PricePerUnit %></td>
                    </tr>
                    <tr>
                        <td>数量:</td>
                        <td><a onclick="updatenum('sub');" href="javascript:void(0);">-</a>
                            <input type="text" value="1" name="quantity" style="width: 30px; text-align: right;"/>
                            <a onclick="updatenum('add');" href="javascript:void(0);">+</a> 件（库存<%=product.Quantity %>件）
                        </td>
                    </tr>
                </table>
                    
                <table>
                    <tr>
                        <td>
                            <div style="margin-right: 9px; border-radius: 2px; border-style: solid; border-width: 1px;
cursor: pointer; display: block; font-family: Hiragino Sans GB,microsoft yahei,sans-serif;
font-size: 16px;
height: 38px;
line-height: 38px;
text-align: center;
width: 134px;
background: #ffe4d0 none repeat scroll 0 0;
border-color: #f0cab6;" >
                                <a data-spm-click="gostr=/tbdetail;locaid=d1" data-addfastbuy="true" class="J_LinkBuy" title="点击此按钮，到下一步确认购买信息"
                                    href="javascript:;" 
                                    style="color: #e5511d;">
                                    立即购买
                                </a>
                            </div>
                        </td>
                        <td>
                            <div style="width: 173px;background: #f40 none repeat scroll 0 0;
border-color: #f40;

border-radius: 2px;
border-style: solid;
border-width: 1px;
cursor: pointer;
display: block;
font-family: Hiragino Sans GB,microsoft yahei,sans-serif;
font-size: 16px;
height: 38px;
line-height: 38px;
text-align: center;">
                                <a data-spm-click="gostr=/tbdetail;locaid=d2" shortcut-effect="click" shortcut-label="加入购物车"
                                    shortcut-key="a" class="J_LinkAdd" title="加入购物车" href="javascript:AddToCart();"
                                    style="color: #fff;" >
                                    <i class="tb-iconfont" style=" font-size: 18px;
            font-style: normal;
            font-weight: 400;
            margin-right: 10px;
            vertical-align: bottom;">ŭ</i>
                                    加入购物车
                                </a>
                            </div>
                        </td>
                    </tr>
                </table>


            </td>
        </tr>
    </table>
        
        
    <table>
        <tr>
            <td>Name:</td>
            <td><%=product.Name %></td>
                    
            <td>PricePerUnit:</td>
            <td><%=product.PricePerUnit %></td>
                    
            <td>NetWeight:</td>
            <td><%=product.NetWeight %></td>
        </tr>
        
        <tr>
            <td>GrossWeight:</td>
            <td><%=product.GrossWeight %></td>
                    
            <td>ProductionDate:</td>
            <td><%=product.ProductionDate %></td>
                    
            <td>Quantity:</td>
            <td><%=product.Quantity %></td>
        </tr>
        
        <tr>
            <td>description:</td>
        </tr>
                
    </table>

    <div>
            
        <%=product.Description %>
            
    </div>


    </form>
</asp:Content>